#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;

int main(int argc, char const *argv[])
{
    // 构造方法
    string s1("hello world");  // 字符串字面量
    string s2(s1);             // 拷贝构造
    string s3(5, 'a');         // 5个a

    cout << "s1 = " << s1 << endl;
    cout << "s2 = " << s2 << endl;
    cout << "s3 = " << s3 << endl;

    s3 = "hello world";
    cout << "s3 = " << s3 << endl;

    s1.insert(11,s3);
    cout << "s1 = " << s1 << endl;

    s1.erase(11,5);
    cout << "s1 = " << s1 << endl;

    s1 += s3;
    cout << "s1 = " << s1 << endl;

    cout << "world第一次出现在:" << s1.find("world") << endl;
    cout << "s3第一次出现在:" << s1.find(s3,0) << endl;

    if (!s1.compare(s3))
    {
        cout << "相同" << endl;
    }
    else
    {
        cout << "不相同" << endl;
    }

    s1 = "123456";
    // cin >> s1;
    int val = stoi(s1);
    cout << "val = " << val << endl;
    cout << typeid(stoi(s1)).name() << endl;

    cout << s1[2] << endl;
    
    return 0;
}
